package Fisica;

import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.JOptionPane;


public abstract class Conexion {
	static String user = "dba";
	static String pass = "sql";
	/**CONFIGURACIONES DE CONEXIONES:
	 * Al 132.147.160.40: solo adminte conexiones al puerto 5000
	 * Al 132.147.160.224 (conexiones localhost): adminte conexiones al puerto 5000 y 2638*/
	// IP SERVER oficial
	static String ipPuertoDB = "132.147.160.40:5000/super7";	
	// IP LOCAL prueba 
//	static String ipPuertoDB = "132.147.160.126:2638/super9_bak";
	static String jdbc = "jdbc:sybase:Tds:"+ipPuertoDB;
//	static String jdbc = "jdbc:sybase:Tds:132.147.160.126:2638/super9_bak";
	static String driver = "com.sybase.jdbc3.jdbc.SybDriver";
	
	public static Connection getConexion(){ //sql consulta a ejecutar.
		Connection cn = null;
		try{
			//retorna 0 si OK, de lo contrario -1
			Class.forName(driver).newInstance();
			
			cn = DriverManager.getConnection(jdbc, user, pass);
			if (cn.isClosed()){
				conectar();
			}
			
		}catch (Exception e){
			System.out.println(e.getMessage());
			
		}
		return cn;
	}
	
	public static Connection conectar(){
	       Connection link = null;
	       try{
	           Class.forName(driver);
	           link = DriverManager.getConnection(jdbc, user, pass);
	       }catch(Exception ex){
	           JOptionPane.showMessageDialog(null, ex);
	       }
	       return link;
	   }
	
	public static String getJDBC(){
		return ipPuertoDB;
	}
	
	
	public static void main(String[] args) {
		

	}

}
